package com.paw.ruoyi.admin.core.util;


import com.paw.ruoyi.admin.common.domain.PageDomain;

/**
 * 表格数据处理
 *
 * @author ruoyi
 */
public class TableSupport {

  /**
   * 当前记录起始索引
   */
  public static final String PAGE_NUM = "pageNum";


  /**
   * 每页显示记录数
   */
  public static final String PAGE_SIZE = "pageSize";

  /**
   * 默认分页
   */
  public static final int DEFAULT_PAGE_NUM = 1;
  /**
   * 默认分页大小
   */
  public static final int DEFAULT_PAGE_SIZE = 10;

  /**
   * 排序列
   */
  public static final String ORDER_BY_COLUMN = "orderByColumn";

  /**
   * 排序的方向 "desc" 或者 "asc".
   */
  public static final String IS_ASC = "isAsc";

  /**
   * 分页参数合理化
   */
  public static final String REASONABLE = "reasonable";

  /**
   * 封装分页对象
   */
  public static PageDomain getPageDomain () {
    PageDomain pageDomain = new PageDomain();
    Integer paramPageNum = ServletUtils.getParameterToInt(PAGE_NUM);
    Integer paramPageSize = ServletUtils.getParameterToInt(PAGE_SIZE);
    int pageNum = paramPageNum != null ? paramPageNum : DEFAULT_PAGE_NUM;
    int pageSize = paramPageSize != null ? paramPageSize : DEFAULT_PAGE_SIZE;
    pageDomain.setPageNum(pageNum);
    pageDomain.setPageSize(pageSize);
    pageDomain.setOrderByColumn(ServletUtils.getParameter(ORDER_BY_COLUMN));
    pageDomain.setIsAsc(ServletUtils.getParameter(IS_ASC));
    pageDomain.setReasonable(ServletUtils.getParameterToBool(REASONABLE));
    return pageDomain;
  }

  public static PageDomain buildPageRequest () {
    return getPageDomain();
  }
}
